import {request, postRequest} from '../services/request.js';
// 公用数据
export default {
	namespaced : true,
	state : {
		// 网络请求加载状态
		loading: false,
		// 保存所有滚动条的数据
		scrolls: {
			scroll: 0,
			channel: 0
		}
	},
	mutations:{
		setLoading(state,payload){
			state.loading = payload;
		},
		setScrolls(state, payload){
			state.scrolls[payload.name] = payload.val;
		}
	},
	actions:{
		async request(context, payload){
			context.commit('setLoading', true);
			const resp = await request(payload.url, payload.query, payload.method||'get');
			if(resp){
				context.commit(payload.where, resp, {root: true});
			}
			context.commit('setLoading', false);
		}
	}
}